﻿@using System.Globalization
@using KPIS.GERP.MVC.Classes
@using KPIS.GERP.SERVICE.Model
@model hrm_ps_absence

@{
    ViewBag.Title = "สร้างคำขอลา";
    var startDate = (Model == null || Model.start_date == null)
        ? DateTime.Now.ToString("dd/MM/yyyy", new CultureInfo("th-TH"))
        : Model.start_date.Value.ToString("dd/MM/yyyy", new CultureInfo("th-TH"));
                                
    var endDate = (Model == null || Model.end_date == null)
        ? DateTime.Now.ToString("dd/MM/yyyy", new CultureInfo("th-TH"))
        : Model.end_date.Value.ToString("dd/MM/yyyy", new CultureInfo("th-TH"));
        
    var startTimeInit = (Model == null || Model.start_time == null) ? "M" : Model.start_time;
    var startTimeData = new SelectList(new List<Object> { new { value = "M", text = "ตั้งแต่ช่วงเช้า" }, new { value = "A", text = "ตั้งแต่ช่วงบ่าย" } }, "value", "text", startTimeInit);
    var endTimeInit = (Model == null || Model.end_time == null) ? "A" : Model.end_time;
    var endTimeData = new SelectList(new List<Object> { new { value = "M", text = "ถึงช่วงเช้า" }, new { value = "A", text = "ถึงช่วงบ่าย" } }, "value", "text", endTimeInit);            
} 

<div style="padding: 0 100px;">
    <div style=" margin-bottom: 30px; float:left;">
        <h2><span class="green">เพิ่ม</span> คำขอลา</h2>
        <div id="form1" >
            @using (Html.BeginForm())
            {
                @Html.HiddenFor(model => model.emp_seq)
                <h4 class="header">แบบฟอร์มการลา</h4>
                <div class="detail" >
                    <fieldset>
                        <table class="info" style="width:600px; " >  
                            <tr>
                                <td class="editor-label">หัวข้อ : </td> 
                                <td class="editor-field" colspan="3">
                                    @Html.Editor("requestTitle", ViewBag.requestTitle as string)
                                </td>
                            </tr>
                            <tr>
                                <td class="editor-label">ผู้ขอลา : </td>  
                                <td class="editor-field" colspan="3">
                                    @Html.DropDownList("requesterEmpSeq", new SelectList(new GERPContext().hrm_ps_employees
                                        .OrderBy(m => m.first_name) 
                                        .Where(m => m.record_status != "D" && m.hrm_ps_employee_statuses.active == "1" )
                                        .ToList(), "emp_seq", "full_name", new SsMng().EmpSeq), new { @Style = "width:100%;" })
                                </td>
                            </tr>
                            <tr>
                                <td class="editor-label">ประเภทคำขอลา : </td>
                                <td class="editor-field" colspan="3"> @Html.DropDownListFor(model => model.absence_type_seq, (IEnumerable<SelectListItem>)ViewBag.AbsenceTypes, new { @Style = "width:100%;" })</td>
                            </tr>
                            <tr>
                                <td class="editor-label">วันเริ่มลา : </td>
                                <td class="editor-field" style="width: 120px">
                                    @Html.EditorFor(model => model.start_date, new { @Value = startDate, @Style = "width:auto;" })
                                </td> 
                                <td class="editor-label"  style="width: 50px" id="caption_time_start">ช่วง : </td>
                                <td class="editor-field" id="field_time_start">
                                    @Html.DropDownListFor(model => model.start_time, startTimeData, new { @Style = "width:100%;" })
                                </td>
                            </tr> 
                            <tr>
                                <td class="editor-label">วันสุดท้ายของการลา : </td>
                                <td class="editor-field">
                                    @Html.EditorFor(model => model.end_date, new { @Value = endDate , @Style = "width:auto;" })
                                </td> 
                                <td class="editor-label" id="caption_time_end"> ช่วง : </td>
                                <td class="editor-field" id="field_time_end">
                                    @Html.DropDownListFor(model => model.end_time, endTimeData, new { @Style = "width:100%;" })
                                </td>
                            </tr>  
                            <tr>
                                <td class="editor-label"></td>
                                <td colspan="3" >
                                    @Html.CheckBox("chbIsFullDay", true) <span style="font-style:italic">(ลาเต็มวัน)</span>
                                </td>
                            </tr>
                            <tr>
                                <td class="editor-label" >ที่อยู่ที่ติดต่อได้ : </td>
                                <td class="editor-field" colspan="3">
                                    @if (@Model == null || @Model.contact_address == null)
                                    {
                                        @Html.TextAreaFor(model => model.contact_address, new { @Style = "width:100%;" })
                                    }
                                    else
                                    {
                                        @Html.TextAreaFor(model => model.contact_address, new { @Value = @Model.contact_address, style = "width:100%;" })
                                    }
                                </td>
                            </tr>  
                            <tr>
                                <td class="editor-label"> รายละเอียด : </td>
                                <td class="editor-field" colspan="3">
                                    @if (@Model == null || @Model.description == null)
                                    {
                                        @Html.TextAreaFor(model => model.description, new { style = "width:100%" })
                                    }
                                    else
                                    {
                                        @Html.TextAreaFor(model => model.description, new { @Value = @Model.description, style = "width:100%" })
                                    } 
                                </td>
                            </tr>     
                        </table>
                    </fieldset> 
                    <div style="margin-left: 100px">
                        <b>@ViewBag.Message</b>
                        @if (Model != null && Model.absence_type_seq.HasValue && !string.IsNullOrWhiteSpace(ViewBag.Sequence))
                        { 
                            <div style="display:inline;">@Html.ActionLink("ยืนยัน", "Confirm", new { emp_seq = Model.emp_seq, absence_seq = Model.absence_seq, status = "P", requestTitle = ViewBag.requestTitle, absence_type_seq = Model.absence_type_seq }) </div>
                            @:|&nbsp;
                            <div style="display:inline;">@Html.ActionLink("ยกเลิก", "Confirm", new { emp_seq = Model.emp_seq, absence_seq = Model.absence_seq, status = "D", requestTitle = ViewBag.requestTitle, absence_type_seq = Model.absence_type_seq }) </div>
                        }
                    </div>
                </div>
                <div class="pnlCommand1">
                    <input type="submit" value="บันทึก" />&nbsp;&nbsp;@Html.ActionLink("กลับไปหน้าข้อมูลใบลา", "Index",null,  new {@class="anchor"})
                </div>
            }
        </div>
    </div>
</div>

@{ ViewBag.RenderValidate = false; }

@section scripts{
        
    <script type="text/javascript" >
         
        jQuery(function ($) {
            
            $(document).ready(function () {

                $(".datepicker").datepicker({
                    dateFormat: 'dd/mm/yy',
                    dayNames: ['อาทิตย์', 'จันทร์', 'อังคาร', 'พุธ', 'พฤหัสบดี', 'ศุกร์', 'เสาร์'],
                    dayNamesMin: ['อา.', 'จ.', 'อ.', 'พ.', 'พฤ.', 'ศ.', 'ส.'],
                    monthNames: ['มกราคม', 'กุมภาพันธ์', 'มีนาคม', 'เมษายน', 'พฤษภาคม', 'มิถุนายน', 'กรกฎาคม', 'สิงหาคม', 'กันยายน', 'ตุลาคม', 'พฤศจิกายน', 'ธันวาคม'],
                    monthNamesShort: ['ม.ค.', 'ก.พ.', 'มี.ค.', 'เม.ย.', 'พ.ค.', 'มิ.ย.', 'ก.ค.', 'ส.ค.', 'ก.ย.', 'ต.ค.', 'พ.ย.', 'ธ.ค.'] 
                }); 

                $("#chbIsFullDay").change(function (e) {
                     
                    if ($(this).is(':checked')) {
                        $("#caption_time_start,#caption_time_end,#field_time_start,#field_time_end").css("visibility", "collapse");
                    } else {
                        $("#caption_time_start,#caption_time_end,#field_time_start,#field_time_end").css("visibility", "visible");
                        $("#start_time").val("M");
                        $("#end_time").val("A");
                    }
                });
                

                $("#requesterEmpSeq").change(function (e) { 
                    $("#requestTitle").val("คำขอลาของ" + $("#requesterEmpSeq option:selected").text());
                });
            });
            
            if ($("#chbIsFullDay").is(':checked')) {
                $("#caption_time_start,#caption_time_end,#field_time_start,#field_time_end").css("visibility", "collapse");
            } else {
                $("#caption_time_start,#caption_time_end,#field_time_start,#field_time_end").css("visibility", "visible");
            }
        });
         
        
    </script>

}
